import {
  LockOutlined,
  UserOutlined,
} from '@ant-design/icons';
import { Button } from 'antd';
import {
  LoginForm,
  ProFormText,
  ProFormSelect,
} from '@ant-design/pro-components';
import { useModel } from "@@/exports";
import { request } from 'umi';
import Cookies from 'js-cookie'
import { history } from 'umi';
import { message, Space, Typography } from 'antd';
import { Auth2LoginAPI } from "@/services/LoginApi";
import { layout } from "@/app";
import { getUserInfo } from "@/utils/format";
import routes_province from "../../../../config/routes_province";
import routes_xk from "../../../../config/routes_xk";
import routes_school from "../../../../config/routes_school";
import * as url from "url";
import { ShowError } from "@/utils/format";
import { fontSize } from "html2canvas/dist/types/css/property-descriptors/font-size";


export default () => {
  const queryString = window.location.search;

  const auth2login = async (queryString: string) => {

    if (queryString === "" || queryString.length === 0) {
      console.log("@智慧平台登录，跳转链接!")
      var link = document.createElement("a");
      link.href = "https://basic.jxeduyun.com/sso-oauth/authorize?appkey=31c478105f364af3ba5c1f0346cbcebf&redirectUri=http://syl.jiangxi.ncu.edu.cn/user/auth2Login&state=1";
      link.rel = "noreferrer";
      link.click();
      return;
    }

    console.log("@开始登录 发送数据!", queryString)
    const req = await Auth2LoginAPI(queryString)
    console.log('@返回数据:', req)
    if (req.token) {
      Cookies.set('userInfo', JSON.stringify(req))
      message.success('登录成功，欢迎您!')
      // location.reload()

      const userInfo = getUserInfo()
      if (userInfo.role === "省厅管理员") {
        location.replace('/home')
      } else if (userInfo.role === "学科填报用户") {
        location.replace('/disci-cons/progress')
      } else {
        location.replace('/home')
      }
    } else {
      ShowError("登录失败！")
      location.replace('/user/login')
    }
  };

  auth2login(queryString)

  return (
    <div>
    </div>
  );
};


